<template>
  <div style="height: 100%;">
    <x-header :left-options="{preventGoBack:true,backText: ''}" @on-click-back="backhome">质量检查单填写</x-header>
    <div class="main-container">
      <!-- <div id="map"></div> -->
      <v-touch v-on:swiperight="onSwipeRight" :swipe-options="{direction: 'horizontal'}">
        <div>
          <group>
            <!-- <cell title="项目部" v-model="pmname" is-link link="prjList1"></cell>
            <cell title="工程项目" v-model="pro" is-link link="prjList1"></cell> -->
            <select-project
                title="项目部"
                formType="inspection"
                module="quality"
                status="add"
                :showValue="true"
                v-model="pmname"
                @selectPro="selectPro"
              ></select-project>
              <div style="height: 1px;background: #eeeeee;"></div>
             <select-project
                title="工程项目"
                formType="inspection"
                module="quality"
                status="add"
                :showValue="true"
                v-model="pro"
                @selectPro="selectPro"
              ></select-project>
            <!-- <popup-picker title='单位工程'
                        v-model="unitId"
                        :data='units'
                        @on-change='setUnitId'
            show-name=true></popup-picker>-->
            <!--  <x-input title="检查单名称"
                   v-model="formName"
                   text-align=right></x-input>
          <x-input title="检查单编号"
                   v-model="formNo"
            text-align=right></x-input>-->
            <popup-picker title="类型" v-model="type" :data="types"></popup-picker>
            <popup-picker title="检查表类型" v-model="checkType" :data="checkTypes"></popup-picker>
            <popup-picker title="检查项目" v-model="checkItem" :data="checkItems"></popup-picker>
            <popup-picker title="检查子项目" v-model="formNo" :data="formNos"></popup-picker>
            <calendar v-model="checkDate" title="检查日期" disable-future @on-change="dateChange"></calendar>
          </group>
          <group title="描述">
            <x-textarea placeholder="请输入一段描述" v-model="DESCRIPTION"></x-textarea>
          </group>
          <group title="检查图片">
            <picture-upload :pageToken="pageToken" v-model="fieldToken"></picture-upload>
          </group>
          <group>
            <cell title="填写人" v-model="name"></cell>
            <cell title="联系电话" v-model="phone"></cell>
            <cell title="填写部门" v-model="dept"></cell>
            <cell title="填写时间" v-model="inputDate"></cell>
          </group>
          <div style="text-align:center;display:flex" class="top-border">
            <button :disabled="isDisable" class="userBack-button_save" @click="saveInspectionInfo">保存</button>
            <Toast :value="toastValue" :is-show-mask="true" text="保存成功" @on-hide="saveSuccess"></Toast>
            <Toast
              :value="toastValueErr"
              :is-show-mask="true"
              :text="err"
              @on-hide="saveErr"
              type="cancel"
              width="200px"
            ></Toast>
          </div>
        </div>
      </v-touch>
    </div>
  </div>
</template>
 
<script>
import * as L from "leaflet";
//Vue.L = Vue.prototype.$L = L
import {
  Group,
  Cell,
  XButton,
  Box,
  GroupTitle,
  Flexbox,
  FlexboxItem,
  Divider,
  Calendar,
  PopupPicker,
  Toast,
  XInput,
  Picker,
  Loading
} from "vux";
var map = null;
var marker = null;
var flag = 0;
export default {
  components: {
    XButton,
    Box,
    GroupTitle,
    Group,
    Flexbox,
    FlexboxItem,
    Divider,
    Group,
    Cell,
    Calendar,
    PopupPicker,
    Toast,
    XInput,
    Picker,
    Loading
  },
  name: "HelloWorld",
  data() {
    return {
      pmid:
        this.$route.query.pmid === ""
          ? this.$route.query.proId
          : this.$route.query.pmid,
      pmname: this.$route.query.pmname,
      pro: this.$route.query.pro,
      proId: this.$route.query.proId,
      centerPosition: this.$route.query.centerPosition,
      site: this.$route.query.centerPosition,
      name: this.$store.state.user.ADUSER_NAME,
      userName: this.$store.state.user.loginId,
      phone: this.$store.state.user.mobil,
      dept: this.$store.state.user.orgName,
      deptId: this.$store.state.user.orgId,
      DESCRIPTION: "",
      pageToken: "",
      fieldToken: "",
      buttonid: "",
      inputDate: this.$store.state.user.loginTime,
      formName: "",
      formNo: [],
      unitId: [],
      unitName: [],
      units: [],
      checkType: [],
      checkTypes: [],
      checkDate: "",
      month: "",
      year: "",
      checkMy: "",
      quarter: "",
      toastValue: false,
      toastValueErr: false,
      err: "",
      checkDateFix: "",
      checkItems: [],
      checkItem: [],
      formNos: [],
      isDisable: false,
      type:[],
      types:[['隐患','建议','亮点']],
      typeOrderId:"",
    };
  },
  methods: {
    selectPro(val){
      console.log(val)
      this.proId = val.id;
      this.pmname = val.pname;
      this.pmid = val.pid === "" ? val.id : val.pid;
      this.pro = val.name;
      this.site = val.site;
    },
    onSwipeRight() {
      this.$router.push("/qualityReport");
    },
    dateChange() {
      var date = this.checkDate;
      this.checkDateFix = this.checkDate + " 00:00:00.000";
      //console.log(this.checkDateFix)
      //this.checkDate=date;
      var month = date.substr(5, 2);
      var year = date.substr(0, 4);
      var checkMy = date.substr(0, 7);
      date = new Date(date);
      var dtMonth = date.getMonth();
      var quarter = 0;
      if (dtMonth < 3) {
        quarter = 1;
      } else if (dtMonth < 6) {
        quarter = 2;
      } else if (dtMonth < 9) {
        quarter = 3;
      } else {
        quarter = 4;
      }
      this.month = month;
      this.year = year;
      this.checkMy = checkMy;
      this.quarter = quarter;
    },
    backhome() {
      if (this.checkNetWork()) {
        this.$router.push({
          path: "/qualityReport",
          query: {
            centerPosition: this.site,
            pro: this.pro,
            proId: this.proId,
            pmname: this.pmname,
            pmid: this.pmid,
            isSelected:true
          }
        });
        this.$vux.loading.hide();
      } else {
        //执行离线状态时的任务
        this.$router.push({
          path: "/offlinequalitylist",
          query: {
            pro: this.pro,
            proId: this.proId,
            pmname: this.pmname,
            pmid: this.pmid,
            centerPosition: this.site
          }
        });
      }
    },
    saveInspectionInfo() {
      this.isDisable = true
      this.err = "";
      if (!this.pro) {
        this.err += "【工程项目】不能为空<br/>";
      }
      if (this.checkDate == "") {
        this.err += "【检查日期】不能为空<br/>";
      }
      // if (this.DESCRIPTION == []) {
      //   this.err += "【描述】不能为空<br/>";
      // }
      // if (this.fieldToken == "") {
      //   this.err += "【检查图片】不能为空<br/>";
      // }
      if(this.type.length == 0){
        this.err += "【类型】不能为空<br/>";
      }
      if (this.checkType.length == 0) {
        this.err += "【检查表名称】不能为空<br/>";
      }
      if (this.checkItem.length == 0) {
        this.err += "【检查项目】不能为空<br/>";
      }
      if (this.formNo.length == 0) {
        this.err += "【检查子项】不能为空<br/>";
      }
      //   if (this.unitName == '') {
      //     this.err += '【单位工程】不能为空<br/>'
      //   }
      if (this.err != "") {
        this.toastValueErr = true;
        this.isDisable = false;
        return false;
      }
      if (this.checkNetWork()) {
        var params = {
          _method: "formService.saveFormData",
          requestEventData: {
            eventType: "formSubmitEvent",
            formType: 1,
            bizObjId: "PMQUALITY_INSPECTION",
            formId: "PMQUALITY_INSPECTION_add",
            buttonId: this.buttonid
          },
          _OBJ_NAME_: "PMQUALITY_INSPECTION",
          _FORM_ID_: "PMQUALITY_INSPECTION_add",
          useType: "add",
          pageToken: this.pageToken,
          formData: {
            objName: "PMQUALITY_INSPECTION",
            pks: ["GUID"],
            data: [
              {
                rowData: [
                  {
                    DataTarget: "GUID",
                    Value: "",
                    OriginalValue: null,
                    PK: true,
                    DataType: "String"
                  },
                  {
                    DataTarget: "FLAG",
                    Value: 0,
                    OriginalValue: null,
                    PK: false,
                    DataType: "int"
                  },
                  {
                    DataTarget: "CENTERPOSITION",
                    Value: this.site,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "FORMNAME",
                    Value: this.formName,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "FORMNO",
                    Value: this.formNo.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PRJNAME",
                    Value: this.pmname,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "SYSPRJID",
                    Value: this.pmid,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "UNITNAME",
                    Value: this.unitName.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "UNITID",
                    Value: this.unitId.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKDATE",
                    Value: this.checkDate + " 00:00:00.000",
                    OriginalValue: null,
                    PK: false,
                    DataType: "TimeStamp"
                  },
                  {
                    DataTarget: "CHECKYEAR",
                    Value: this.year,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKMONTH",
                    Value: this.month,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKYEARANDMONTH",
                    Value: this.checkMy,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKTYPE",
                    Value: this.checkType.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "DESCRIPTION",
                    Value: this.DESCRIPTION,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "ATTACHMENTS",
                    Value: this.fieldToken,
                    OriginalValue: null,
                    PK: false,
                    DataType: "Store.ecidiDoc"
                  },
                  {
                    DataTarget: "INPUTERFULLNAME",
                    Value: this.name,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTERNAME",
                    Value: this.userName,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PHONENUM",
                    Value: this.phone,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTERDEPTNAME",
                    Value: this.dept,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTERDEPTID",
                    Value: this.deptId,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTDATE",
                    Value: this.inputDate,
                    OriginalValue: null,
                    PK: false,
                    DataType: "TimeStamp"
                  },
                  {
                    DataTarget: "PROJECTNAME",
                    Value: this.pro,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PROJECTID",
                    Value: this.proId,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKITEM",
                    Value: this.checkItem.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "TYPE",
                    Value: this.type.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "TYPEORDERID",
                    Value: this.typeOrderId,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKQUARTER",
                    Value: this.quarter,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "ISTHIRDPART",
                    Value: '0',
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  }
                ],
                children: []
              }
            ]
          },
          _ATTACHMENT_DELETE_IDS_: "",
          formInfo: {
            GUID: "",
            FLAG: "0",
            CENTERPOSITION: this.site,
            FORMNAME: this.formName,
            FORMNO: this.formNo.toString(),
            PRJNAME: this.pmname,
            SYSPRJID: this.pmid,
            UNITNAME: this.unitName.toString(),
            UNITID: this.unitId.toString(),
            CHECKDATE: this.checkDateFix,
            CHECKYEAR: this.year,
            CHECKMONTH: this.month,
            CHECKYEARANDMONTH: this.checkMy,
            CHECKTYPE: this.checkType,
            DESCRIPTION: this.DESCRIPTION,
            ATTACHMENTS: this.fieldToken,
            INPUTERFULLNAME: this.name,
            INPUTERNAME: this.userName,
            PHONENUM: this.phone,
            INPUTERDEPTNAME: this.dept,
            INPUTERDEPTID: this.deptId,
            INPUTDATE: this.inputDate,
            PROJECTID: this.proId,
            PROJECTNAME: this.pro,
            CHECKITEM: this.checkItem.toString(),
            TYPE:this.type.toString(),
            TYPEORDERID:this.typeOrderId,
            CHECKQUARTER:this.quarter,
            ISTHIRDPART: '0'
          }
        };
        let json = {
          FixJSON: JSON.stringify(params)
        };
        this.$ajax({
          url: this.COMMON_URL, //+ "?_viewId=PMQUALITY_INSPECTION",
          method: "post",
          // data: this.signMD5(json)
          data:json
        })
          .then(res => {
            console.log('返回值',res);
            this.$vux.loading.show({
            text:"Loading"
          })
            this.toastValue = true;
          })
          .catch(err => {
            alert(err);
          });
      } else {
        //执行离线状态时的任务
        let offline = this.$store.state.offlineflieurl;
        console.log("quality", this.fieldToken);
        console.log("offline", offline);

        let urlOFFLINE = [];
        for (let i = 0; i < offline.length; i++) {
          let flies = offline[i].url.replace(/\./g, "||");
          urlOFFLINE.push(flies);
        }
        let offlineStr = urlOFFLINE.join(",");
        console.log("urlOFFLINE", urlOFFLINE);
        this.$store.state.SQLiteDB.transaction(
          tx => {
            tx.executeSql(
              'INSERT INTO PMQUALITY_INSPECTION (GUID, FLAG, CENTERPOSITION, FORMNAME, FORMNO, PRJNAME, SYSPRJID, UNITNAME ,UNITID,CHECKDATE,CHECKYEAR,CHECKMONTH,CHECKYEARANDMONTH,CHECKTYPE,DESCRIPTION,ATTACHMENTS,INPUTERFULLNAME,INPUTERNAME,PHONENUM,INPUTERDEPTNAME,INPUTERDEPTID,INPUTDATE,PROJECTNAME,PROJECTID,CHECKITEM,FILEURL,TYPE,TYPEORDERID,ISTHIRDPART,CHECKQUARTER) VALUES ("' +
                this.guid() +
                '","' +
                "0" +
                '","' +
                this.site +
                '","' +
                this.formName +
                '","' +
                this.formNo.toString() +
                '","' +
                this.pmname +
                '","' +
                this.pmid +
                '","' +
                this.unitName.toString() +
                '","' +
                this.unitId.toString() +
                '","' +
                this.checkDateFix +
                '","' +
                this.year +
                '","' +
                this.month +
                '","' +
                this.checkMy +
                '","' +
                this.checkType +
                '","' +
                this.DESCRIPTION +
                '","' +
                this.fieldToken +
                '","' +
                this.name +
                '","' +
                this.userName +
                '","' +
                this.phone +
                '","' +
                this.dept +
                '","' +
                this.deptId +
                '","' +
                this.inputDate +
                '","' +
                this.pro +
                '","' +
                this.proId +
                '","' +
                this.checkItem.toString() +
                '","' +
                offlineStr +
                '","' +
                this.type.toString() +
                '","' +
                this.typeOrderId +
                '","' +
                "0" +
                '","' +
                this.quarter +
                '")'
            );
            tx.executeSql(
              "SELECT * FROM PMQUALITY_INSPECTION",
              [],
              (tx, result) => {
                console.log("myQUALITYlist", result);
              }
            );
          },
          err => {
            console.log(err);
          }
        );
        this.toastValue = true;
      }
    },
    /**
     * 获取检查表类型
     */
    getCheckTypes() {
      if (this.checkNetWork()) {
        console.log("正常工作！");
        // debugger
        // let params = {
        //   FixJSON: {
        //     _method: "component.getBatchDatas",
        //     _param: {
        //       controls: {
        //         CHECKTYPE: {
        //           orgConfig: {
        //             Filter: "1=1",
        //             Fields: "CODE_ID,CODE_NAME",
        //             OrderList: [{ order: "asc", field: "CODE_ORDER" }],
        //             BizObj: "FIX_SYS_CODE",
        //             Service: "selectMore_defauld",
        //             componentType: "ECIDIHTMLSelect"
        //           },
        //           dataConfig: {
        //             Method: "component.getListData",
        //             Param: {
        //               bizObj: "FIX_SYS_CODE",
        //               service: "selectMore_defauld",
        //               fields: "CODE_ID,CODE_NAME",
        //               filter: "TYPE_ID='PMQUALITY_INSPECTION.CHECKTYPE'",
        //               currentPageIndex: 1,
        //               pageSize: 999999,
        //               orderList: [{ order: "asc", field: "CODE_ORDER" }],
        //               QueryFormData: ""
        //             },
        //             componentType: "ECIDIHTMLSelect"
        //           },
        //           storeType: "Data"
        //         }
        //       }
        //     }
        //   }
        // };
        //--------------加密参数开始（加密用一下参数形式）
        let params = {
          _method: "component.getBatchDatas",
          _param: {
            controls: {
              CHECKTYPE: {
                orgConfig: {
                  Filter: "1=1",
                  Fields: "CODE_ID,CODE_NAME",
                  OrderList: [{ order: "asc", field: "CODE_ORDER" }],
                  BizObj: "FIX_SYS_CODE",
                  Service: "selectMore_defauld",
                  componentType: "ECIDIHTMLSelect"
                },
                dataConfig: {
                  Method: "component.getListData",
                  Param: {
                    bizObj: "FIX_SYS_CODE",
                    service: "selectMore_defauld",
                    fields: "CODE_ID,CODE_NAME",
                    filter: "TYPE_ID='PMQUALITY_INSPECTION.CHECKTYPE'",
                    currentPageIndex: 1,
                    pageSize: 999999,
                    orderList: [{ order: "asc", field: "CODE_ORDER" }],
                    QueryFormData: ""
                  },
                  componentType: "ECIDIHTMLSelect"
                },
                storeType: "Data"
              }
            }
          }
        };
        let json = {
          FixJSON: JSON.stringify(params)
        };
        //---------------------加密参数结束
        //加密时url后不能加"****"只能是this.COMMON_URL
        this.$ajax({
          url: this.COMMON_URL, //+ "?_viewId=PMQUALITY_INSPECTION_list",
          method: "post",
          // params: params
          // params: this.signMD5(json)
          data:json
        }).then(res => {
          let types = res.data.datas.CHECKTYPE;
          for (let i = 0; i < types.length; i++) {
            this.checkTypes.push(types[i].CODE_NAME);
          }
          this.checkTypes = [this.checkTypes];
        });
      } else {
        //执行离线状态时的任务
        console.log("离线工作！");
        this.$store.state.SQLiteDB.transaction(tx => {
          tx.executeSql(
            "SELECT * FROM PMQUALITY_CHECKTYPE ",
            [],
            (tx, result) => {
              //console.log('pro',result)
              let subPrj = result.rows;
              var i = 0;
              for (i = 0; i < subPrj.length; i++) {
                  this.checkTypes[i] = [subPrj.item(i).CODE_NAME];
                }
              this.checkTypes = [this.checkTypes];
            }
          );
        });
      }
    },
    /**
     * 获取单位工程相关信息
     * param{string}sysprjid 项目编号
     */
    getUnitNames(sysprjid) {
      let params = {
        FixJSON: {
          _method: "component.getListData",
          _param: {
            bizObj: "PMQUALITY_UNIT",
            service: "selectMore",
            fields: "*",
            filter: "1=1 and SYSPRJID='" + sysprjid + "'",
            currentPageIndex: 1,
            pageSize: 50,
            orderList: [],
            QueryFormData: ""
          }
        }
      };
      this.$ajax({
        url: this.COMMON_URL,
        method: "post",
        params: params
      }).then(res => {
        let units = res.data.datas;
        for (let i = 0; i < units.length; i++) {
          let obj = {};
          obj.name = units[i].UNITNAME;
          obj.value = units[i].UNITID;
          this.units.push(obj);
        }
        this.units = [this.units];
      });
    },
    /**
     * 设置unitId
     */
    setUnitId(value) {
      for (let i = 0; i < this.units[0].length; i++) {
        if (this.units[0][i].value === value.join("").toString()) {
          this.unitName.push(this.units[0][i].name);
          break;
        }
      }
    },
    saveSuccess() {
      this.backhome();
    },
    saveErr() {
      this.toastValueErr = false;
    },
    /**
     * 设置默认的检查日期，格式为xxxx-xx-xx
     */
    setDefautlDate() {
      let now = new Date();
      let month = now.getMonth() + 1;
      let day = now.getDate();
      let hour = now.getHours();
      let min = now.getMinutes();
      let sec = now.getSeconds();
      if (month < 10) {
        month = "0" + month;
      }
      if (day < 10) {
        day = "0" + day;
      }
      if (hour < 10) {
        hour = "0" + hour;
      }
      if (min < 10) {
        min = "0" + min;
      }
      if (sec < 10) {
        sec = "0" + sec;
      }
      this.checkDate = now.getFullYear() + "-" + month + "-" + day;
      this.inputDate = now.getFullYear() + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
      console.log(this.inputDate)
      this.dateChange();
    },
    /**
     * 根据检查表类型获取检查项
     */
    getCheckItems(value) {
      if (this.checkNetWork()) {
        // let params = {
        //   FixJSON: {
        //     _method: "component.getListData",
        //     _param: {
        //       bizObj: "PMQUALITY_INSPECT_ITEM",
        //       service: "selectMore",
        //       fields: "INSPECTITEM",
        //       filter: "INSPECTTYPE='" + value + "'",
        //       currentPageIndex: 1,
        //       pageSize: 999999,
        //       orderList: [{ order: "asc", field: "INSPECTITEM" }],
        //       QueryFormData: ""
        //     }
        //   }
        // };
        let params = {
          _method: "component.getListData",
          _param: {
            bizObj: "PMQUALITY_INSPECT_ITEM",
            service: "selectMore",
            fields: "INSPECTITEM",
            filter: "INSPECTTYPE='" + value + "'",
            currentPageIndex: 1,
            pageSize: 999999,
            orderList: [{ order: "asc", field: "INSPECTITEM" }],
            QueryFormData: ""
          }
        };
        let json = {
          FixJSON: JSON.stringify(params)
        };
        console.log(json)
        this.$ajax({
          url: this.COMMON_URL,
          method: "post",
          // params: params
          // params: this.signMD5(json)
          data: json
        }).then(res => {
          console.log(res)
          let data = res.data.datas;
          this.checkItems = [];
          if (data.length !== 0) {
            for (let i = 0; i < data.length; i++) {
              this.checkItems.push(data[i].INSPECTITEM);
            }
            this.checkItems = [this.checkItems];
          }
        });
      } else {
        //执行离线状态时的任务
        console.log("离线工作！");
        this.$store.state.SQLiteDB.transaction(tx => {
          tx.executeSql(
            'SELECT * FROM PMQUALITY_CHECKITEM WHERE INSPECTTYPE = "' +
              value +
              '"',
            [],
            (tx, result) => {
              let subPrj = result.rows;
              var i = 0;
              this.checkItems = [];
              if (subPrj.length !== 0) {
                  for (i = 0; i < subPrj.length; i++) {
                    this.checkItems[i] = [subPrj.item(i).INSPECTITEM];
                  }
                  this.checkItems = [this.checkItems];
                }
            }
          );
        });
      }
    },
    /**
     * 根据检查项获取检查子项
     */
    getCheckChilds(checkItem) {
      if (this.checkNetWork()) {
        // let params = {
        //   FixJSON: {
        //     _method: "component.getListData",
        //     _param: {
        //       bizObj: "PMQUALITY_INSPECT_TYPECHILD_DETAIL",
        //       service: "selectMore",
        //       fields: "CHILDINSPECTITEM",
        //       filter: "INSPECTITEM='" + checkItem + "'",
        //       currentPageIndex: 1,
        //       pageSize: 999999,
        //       orderList: [{ order: "asc", field: "CHILDINSPECTITEM" }],
        //       QueryFormData: ""
        //     }
        //   }
        // };
        let params = {
          _method: "component.getListData",
          _param: {
            bizObj: "PMQUALITY_INSPECT_TYPECHILD_DETAIL",
            service: "selectMore",
            fields: "CHILDINSPECTITEM",
            filter: "INSPECTITEM='" + checkItem + "' and FORMTYPE = '" + this.checkType + "'",
            currentPageIndex: 1,
            pageSize: 999999,
            orderList: [{ order: "asc", field: "CHILDINSPECTITEM" }],
            QueryFormData: ""
          }
        };
        let json = {
          FixJSON: JSON.stringify(params)
        };
        this.$ajax({
          url: this.COMMON_URL,
          method: "post",
          // params: params
          // params: this.signMD5(json)
          data: json
        }).then(res => {
          console.log("检查子项目",res);
          let data = res.data.datas;
          this.formNos = [];
          if (data.length !== 0) {
            for (let i = 0; i < data.length; i++) {
              this.formNos.push(data[i].CHILDINSPECTITEM);
            }
            this.formNos = [this.formNos];
          }
        });
      } else {
        //执行离线状态时的任务
        this.$store.state.SQLiteDB.transaction(tx => {
          tx.executeSql(
            'SELECT * FROM PMQUALITY_CHECKCHILDS WHERE INSPECTITEM = "' +
              checkItem +
              '" and FORMTYPE = "' + this.checkType + '"',
            [],
            (tx, result) => {
              let subPrj = result.rows;
              var i = 0;
              this.formNos = [];
              if (subPrj.length !== 0) {
                  for (i = 0; i < subPrj.length; i++) {
                    this.formNos[i] = [subPrj.item(i).CHILDINSPECTITEM];
                  }
                  this.formNos = [this.formNos];
                }
            }
          );
        });
      }
    }
  },
  mounted() {
    this.setDefautlDate();
    //页面挂载时加载检查项目和单位工程
    this.getCheckTypes();
    if (this.$route.query.proId !== undefined) {
      this.getUnitNames(this.$route.query.proId);
    }
    var greenIcon = L.icon({
      iconUrl: "../src/assets/img/sign-in.png",
      iconSize: [26, 44], // size of the icon
      iconAnchor: [17, 48] // point of the icon which will correspond to marker's location
      //popupAnchor:  [-3, -76] // point from which the popup should open relative to the iconAnchor
    });
    this.pageToken = this.guid(); //this.sPageToken();
    // this.fieldToken = this.guid();
    this.buttonid = this.guid();
    console.log("jahsdkjasdkjh" + this.centerPosition);
    map = L.map("map", {
      center: [22.521671, 113.895794],
      zoom: 13
    });
    L.tileLayer(
      "http://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}",
      //  "http://t0.tianditu.gov.cn/vec_c/wmts?tk=2528436969e251e7e601cb6989d0b8ee",
      {
        subdomains: ["1", "2", "3", "4"],
        attribution: "高德"
      }
    ).addTo(map);
    map.on("click", onMapClick);
    let th = this;
    function onMapClick(e) {
      if (marker) {
        map.removeLayer(marker);
      }
      marker = new L.Marker(e.latlng, { icon: greenIcon }).addTo(map);
      map.addLayer(marker);
      th.site =
        "LatLng(" +
        e.latlng.lat.toString().substr(0, 8) +
        "," +
        e.latlng.lng.toString().substr(0, 9) +
        ")";
    }
    var locate = this.centerPosition;
    var long = locate.slice(locate.indexOf("(") + 1, locate.indexOf(","));
    var latitude = locate.slice(locate.indexOf(",") + 2, locate.indexOf(")"));
    if (marker) {
      map.removeLayer(marker);
    }
    marker = new L.Marker([long, latitude], { icon: greenIcon }).addTo(map);
    map.addLayer(marker);
    map.panTo([long, latitude]);
  },
  watch: {
    centerPosition: {
      handler(newval) {
        var locate = this.centerPosition;
        var long = locate.slice(locate.indexOf("(") + 1, locate.indexOf(","));
        var latitude = locate.slice(
          locate.indexOf(",") + 2,
          locate.indexOf(")")
        );
        if (marker) {
          map.removeLayer(marker);
        }
        marker = new L.Marker([long, latitude], { icon: greenIcon }).addTo(map);
        map.addLayer(marker);
      }
    },
    checkType: {
      handler(newVal) {
        if (newVal.length !== 0) {
          this.getCheckItems(newVal.toString());
        } else {
          this.checkItems = [];
        }
        this.checkItem = [];
      }
    },
    checkItem: {
      handler(newVal) {
        if (newVal.length !== 0) {
          this.getCheckChilds(newVal.toString());
        } else {
          this.formNos = [];
        }
        this.formNo = [];
      }
    },
    type:{
      handler(newVal){
        if(newVal.toString() == '隐患'){
          this.typeOrderId = '1';
        }else if(newVal.toString() == '建议'){
          this.typeOrderId = '2';
        }else{
          this.typeOrderId = '3';
        }
      }
    }
  }
};
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
/* .transition-view /deep/.weui-cells__title {
      margin-top: 0.77em;
    margin-bottom: 0.3em;
    padding-left: 15px;
    padding-right: 15px;
    color: #353535;
    font-size: 14px;
} */
/* .transition-view /deep/ .vux-header .vux-header-left .left-arrow:before {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1px solid rgba(0, 0, 0, 0.8);
  border-width: 1px 0 0 1px;
  -webkit-transform: rotate(315deg);
  transform: rotate(315deg);
  top: 8px;
  left: 7px;
}
.transition-view /deep/ .vux-header .vux-header-title {
  line-height: 40px;
  text-align: center;
  font-size: 18px;
  font-weight: 400;
  color: #333;
} */
.top-border{
  border-top: 1px solid #f5f5f5
}
.userBack-button_save{
      width: 60%;
      height: 40px;
      background-color: #4D86FF; 
      border-radius: 2pt;
      border: 1pt solid #4D86FF;
      margin-top: 20pt;
      color: #FFFFFF;
      font-size: 15px;
      margin-right: auto;
      margin-left: auto;
      margin-bottom: 20pt;
}

#map {
  width: 100%;
  height: 25%;
}
.content {
  width: 100%;
  height: 75%;
}
</style>